package com.zyh.controller;



import com.zyh.pojo.Post;
import com.zyh.pojo.User;
import com.zyh.service.FollowService;
import com.zyh.service.PostService;
import org.apache.shiro.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.List;

/**
 * 路由控制器
 */
@Controller
public class RouterController {
    @Autowired
    PostService postService;
    @Autowired
    FollowService followService;
    @GetMapping("/")
    public String index(Model model){
        String loginUserName= (String) SecurityUtils.getSubject().getPrincipal();
        List<Post> posts=postService.findPostsByUserName(loginUserName);
        model.addAttribute("posts",posts);
        //获取粉丝
        List<User> followers=followService.followers(loginUserName);
        //获取关注者
        List<User> followings=followService.followings(loginUserName);
        model.addAttribute("followers",followers);
        model.addAttribute("followings",followings);
        return "index";
    }
    @GetMapping("/signup")
    public String signup(){
        return "signup";
    }


}
